﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Linq;

public partial class Admin_QuanLyMonHoc : System.Web.UI.Page
{
    DataClassesDataContext data = new DataClassesDataContext();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            LoadDanhSachMonHoc();
        }
    }

    private void LoadDanhSachMonHoc()
    {
        GridView_MonHoc.DataSource = data.tbl_MONHOCs;
        GridView_MonHoc.DataBind();
    }

    protected void GridView_MonHoc_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        try
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                e.Row.Attributes.Add("onmouseover", "this.setAttribute('bgColor', this.style.backgroundColor); this.style.backgroundColor = '#FF6600';");
                e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor = this.getAttribute('bgColor');");
                tbl_MONHOC mh = e.Row.DataItem as tbl_MONHOC;
                (e.Row.FindControl("ImageButton2") as ImageButton).CommandArgument = mh.MsMonHoc.ToString();
            }
        }
        catch { }
    }
    protected void GridView_MonHoc_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        GridView_MonHoc.PageIndex = e.NewPageIndex;
        LoadDanhSachMonHoc();
    }
    protected void GridView_MonHoc_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "MyDelete")
        {
            DataClassesDataContext data = new DataClassesDataContext();
            string EID = Convert.ToString(e.CommandArgument);

            data.tbl_MONHOCs.DeleteOnSubmit(data.tbl_MONHOCs.Single(p => p.MsMonHoc == EID));

            data.SubmitChanges();
            LoadDanhSachMonHoc();
        }
    }
}
